using System;

using Sce.PlayStation.Core;
using Sce.PlayStation.Core.Graphics;
using Sce.PlayStation.Core.Imaging;
using Sce.PlayStation.HighLevel.GameEngine2D;
using Sce.PlayStation.HighLevel.GameEngine2D.Base;

namespace UWSGameJame
{
	
	// This class based on code from www.gamefromscratch.com
	// Used to track Frames Per Second
 	public class FPS : SpriteUV
 	{
		
  		TextureInfo ti;
  
  		public FPS ()
  		{
  			Texture2D texture = new Texture2D(150,1000,false, PixelFormat.Rgba);
   			ti = new TextureInfo(texture);
   
   			this.TextureInfo = ti;
   			this.Quad.S = new Sce.PlayStation.Core.Vector2(150,100);
   			Scheduler.Instance.ScheduleUpdateForTarget(this,1,false);
  		}
		
		public void moveRight(float dx)
		{
			this.Position = new Vector2(this.Position.X + dx, this.Position.Y);
		}
		
		public void moveUp(float dy)
		{
			this.Position = new Vector2(this.Position.X, this.Position.Y + dy);
		}
		
		public void move(float dx, float dy)
		{
			this.Position = new Vector2(this.Position.X + dx, this.Position.Y + dy);
		}
  
  		public override void Update (float dt)
  		{
   			ti.Dispose();
  			Image img = new Image(ImageMode.Rgba, new ImageSize(150,100),
                         new ImageColor(255,255,255,0));
   			
			img.DrawText("FPS:" + (1/dt).ToString(), 
                new ImageColor(255,255,255,255),
                new Font(FontAlias.System,32,FontStyle.Bold),
                new ImagePosition(0,0));
   
   			Texture2D texture = new Texture2D(150,100,false,
                                     PixelFormat.Rgba);
      		texture.SetPixels(0,img.ToBuffer(),PixelFormat.Rgba);
   			img.Dispose();
   			ti = new TextureInfo(texture);
   			this.TextureInfo  = ti;

   			base.Update (dt);
  		}
 	}
}

